/*
package com.itheima.aop;

import com.itheima.common.UserHolder;
import com.itheima.pojo.commonEntity;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Slf4j
@Aspect
@Component
public class CommonColumnAdvice {
    @Pointcut("execution(* com.itheima.controller.*Controller.save*(..))"+
            "||"+
            "execution(* com.itheima.controller.*Controller.update*(..))")
    public void pt(){}

    @Around("pt()")
    public Object modifyColumn(ProceedingJoinPoint pjp){
        log.info("aop,执行了...");
        Object proceed = null;
        try {
            //1.获取参数对象
            Object[] args = pjp.getArgs();
            //2.将controller方法形参中的第一个参数复制给自定义变量
            commonEntity obj = (commonEntity) args[0];
            Long id = UserHolder.get();
            //3.获取标签上的方法名
            String name = pjp.getSignature().getName();//标签，方法名
            //新增
            if (name.startsWith("save")){
                obj.setCreateTime(LocalDateTime.now());
                obj.setCreateUser(id);
            }
            obj.setUpdateTime(LocalDateTime.now());
            obj.setUpdateUser(id);
            proceed = pjp.proceed(args);
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        return proceed;
    }
}
*/
